<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">委托方</label>
                        <div class="layui-input-block">
                            <input type="text" name="lian_unit" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>




    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('项目票税汇总');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_piao_engin_hui_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,{field: 'name', title: '项目名称',fixed:'left'}
                ,{field: 'engin_chanid_name', title: '项目所属单位'}
                ,{field: 'lian_unit', title: '委托方'}
                ,{field: 'faer', title: '合同甲方'}
                ,{field: 'shihemoney', title: '合同金额(元)',align:'right',totalRow: true,event: 'contract_shi',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.shihemoney)+'</span>';
                    }}
                ,{field: 'shirate', title: '合同税率(%)'}

                ,{field: 'gonghuifee', title: '回款金额(元)',totalRow: true,align:'right',event: 'income_engin_gong',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.gonghuifee)+'</span>';
                    }}
                ,{field: 'piao_kai_fee', title: '开票金额不含税(元)',align:'right',totalRow: true,event: 'piao_kai_detail',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.piao_kai_fee)+'</span>';
                    }}
                ,{field: 'piao_kai_ratefee', title: '销项税额(元)',align:'right',totalRow: true,event: 'piao_kai_detail',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.piao_kai_ratefee)+'</span>';
                    }}
                ,{field: 'piao_kai_money', title: '开票金额含税(元)',align:'right',totalRow: true,event: 'piao_kai_detail',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.piao_kai_money)+'</span>';
                    }}
                ,{field: 'piao_shou_money', title: '进项票金额含税(元)',align:'right',totalRow: true,event: 'piao_shou_detail',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.piao_shou_money)+'</span>';
                    }}
                ,{field: 'piao_shou_ratefee', title: '进项税额(元)',align:'right',totalRow: true,event: 'piao_shou_detail',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.piao_shou_ratefee)+'</span>';
                    }}

                ,{field: 'zeng_shui', title: '增值税(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.zeng_shui);}}
                ,{field: 'chengjian', title: '城建税(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.chengjian);}}
                ,{field: 'jiaofu', title: '教育费附加(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.jiaofu);}}
                ,{field: 'dijiao', title: '地方教育费(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.dijiao);}}

                ,{field: 'yinhua', title: '销项印花税(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.yinhua);}}
                ,{field: 'jinhua', title: '进项印花税(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.jinhua);}}
                ,{field: 'shuili', title: '水利基金(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.shuili);}}
                ,{field: 'canbao', title: '残保金(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.canbao);}}
                ,{field: 'gonghui', title: '工会经费(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.gonghui);}}
                ,{field: 'jiaopei', title: '教培费(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.jiaopei);}}
                ,{field: 'qisuo', title: '企业所得税(元)',hide:true,align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.qisuo);}}
                ,{field: 'allshui', title: '税金合计(元)',align:'right',totalRow: true,event: 'piao_kai_detail2',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.allshui)+'</span>';
                    }}

                ,{field: 'yingshuijinfee', title: '应收税费(元)',align:'right',totalRow: true,event: 'piao_kai',templet: function(d){
                    return '<span class="colorlan">'+parseFormatNum(d.yingshuijinfee)+'</span>';
                }}
                ,{field: 'yikoushui', title: '已收税费(元)',align:'right',totalRow: true,event: 'tai_neiming',templet: function(d){
                        return '<span class="colorlan">'+parseFormatNum(d.yikoushui)+'</span>';
                    }}

                ,{field: 'daikoushui', title: '待收税费(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.daikoushui);}}
                ,{field: 'piaorate', title: '应交成本票比例(%)'}
                ,{field: 'piaorate_money', title: '应提供成本票总额(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.piaorate_money);}}
                ,{field: 'yingbupiao', title: '应补成本票(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.yingbupiao);}}
                ,{field: 'charate', title: '成本票差额费比例(%)',align:'right',totalRow: true,templet: function(d){return d.charate;}}
                ,{field: 'chengchafee', title: '成本票差额费(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.chengchafee);}}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        table.on('tool(datalist)',function (obj) {
            var data = obj.data;
            if(obj.event === 'contract_shi'){
                openNavPage('施工合同信息','contract_shi/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'income_engin_gong'){
                openNavPage('项目工程回款信息','income_engin/index.php?enginid='+data.id+'&status=1&gongkuan=1');
            }
            if(obj.event === 'piao_kai_detail'){
                openNavPage('项目开票明细信息','piao_kai/detail.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'piao_kai_detail2'){
                openNavPage('项目开票明细信息','piao_kai/detail.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'piao_shou_detail'){
                openNavPage('项目收票明细信息','piao_shou/detail.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'piao_kai'){
                openNavPage('项目开票信息','piao_kai/index.php?enginid='+data.id+'&status=1');
            }
            if(obj.event === 'tai_neiming'){
                openNavPage('扣款明细信息','tai_neiming/index.php?enginid='+data.id+'&status=1&feitype='+encodeURI('税费'));
            }

        });

        listTableSearch(form, table);
    });



    function auth_but_func_she(buttitle){
        var checkStatus = layui.table.checkStatus('datalist').data;
        if(checkStatus.length != 1){
            facade.error(buttitle + "：请选择单条数据");return false;
        }
        openPageEdit('../engin/she.php?close=1&id='+checkStatus[0].id);
    }
    function auth_but_func_suan(buttitle){
        openNavPage('税费计算器','engin/suan.php')
    }

</script>
</body>
</html>
